/*
 * @lc app=leetcode.cn id=2511 lang=cpp
 *
 * [2511] 最多可以摧毁的敌人城堡数目
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
    int find(vector<int> &forts, int startIndex)
    {
        for (size_t i = startIndex; i < forts.size(); i++)
        {
            if (forts[i] != 0)
                return i;
        }
        return forts.size();
    }

public:
    int captureForts(vector<int> &forts)
    {
        int l = find(forts, 0);
        int r = find(forts, l + 1);
        int ans = 0;
        while (r < forts.size())
        {
            if (forts[l] != forts[r])
            {
                ans = max(ans, r - l - 1);
            }

            l = r;
            r = find(forts, l + 1);
        }
        return ans;
    }
};
// @lc code=end
